<template>
    <Card>
        <p slot="title">技师审核</p>
        <div class="search-con search-con-top">
            技师信息：
            <Input placeholder="请输入技师昵称、手机号" v-model="search.search" style="width: 200px; margin-left: 10px;"></Input>
            审核状态：
            <Select style="width:120px" v-model="search.status">
                <Option value="">全部</Option>
                <Option value="0">待审核</Option>
                <Option value="1">审核通过</Option>
                <Option value="2">审核拒绝</Option>
            </Select>

            <Button type="primary" icon="ios-search" style="margin-left: 10px;" @click="getList">搜索</Button>
            <Button @click="reset" type="success" icon="ios-refresh" style="margin-left: 10px;">刷新</Button>
        </div>
        <!-- <Button @click="reset" type="success" style="margin: 10px 0;">删除所选</Button> -->
        <Table :columns="columns" :data="list" ref="selection" border style="margin-top: 10px;">
            <template slot-scope="{ row , index}" slot="techSlot">
                <img :src="baseImgeUrl + row.tech_avatar" style="width: 60px;height: 60px;"
                    @click="showImg(baseImgeUrl + row.tech_avatar)" />

            </template>
            <template slot-scope="{ row , index}" slot="imgSlot">
                <div v-if="row.type == 1">
                    <img :src="baseImgeUrl + row.image.card_back_img" style="width: 60px;height: 60px;"
                        @click="showImg(baseImgeUrl + row.image.card_back_img)" />
                    <img :src="baseImgeUrl + row.image.card_front_img" style="width: 60px;height: 60px;margin-left: 10px;"
                        @click="showImg(baseImgeUrl + row.image.card_front_img)" />
                </div>
            </template>
            <template slot-scope="{ row , index}" slot="imgSlot1">
                <div v-if="row.type == 2">
                    <img :src="baseImgeUrl + row.image.health_img" style="width: 60px;height: 60px;"
                        @click="showImg(baseImgeUrl + row.image.health_img)" />
                </div>
            </template>
            <template slot-scope="{ row , index}" slot="imgSlot2">
                <div v-if="row.type == 3">
                    <img :src="baseImgeUrl + row.image.certification_img" style="width: 60px;height: 60px;"
                        @click="showImg(baseImgeUrl + row.image.certification_img)" />
                </div>
            </template>
            <template slot-scope="{ row , index}" slot="imgSlot3">
                <div v-if="row.type == 4">
                    <div @click="showImgDao(row)">
                        <span style="color: blue;font-size: 15px;text-decoration:underline;cursor:pointer;">查看图片</span>
                    </div>
                </div>
            </template>
            <template slot-scope="{ row , index}" slot="imgSlot4">
                <div v-if="row.type == 5">
                    <img :src="baseImgeUrl + row.image" style="width: 60px;height: 60px;"
                        @click="showImg(baseImgeUrl + row.image)" />
                </div>
            </template>
            <template slot-scope="{ row , index}" slot="makeSlot">
                <Button type="primary" size="small" v-if="row.status == 0" @click="audit(row.id, 1)">通过</Button>
                <Button type="error" size="small" style="margin-left: 10px;" v-if="row.status == 0"
                    @click="audit(row.id, 2)">驳回</Button>
            </template>
        </Table>
        <br>

        <Page :total="total" show-sizer show-total show-elevator @on-change="changePage" @on-page-size-change="changeSize">
        </Page>
        <Modal v-model="imgShow" width="330px" :closable="false">
            <img :src="imgShowUrl" style="width: 300px;">
        </Modal>

        <Modal v-model="showPaymentInfo" title="生活照片">
            <p v-for="item in imgArr">
                <img :src="baseImgeUrl + item" style="width: 500px;">
            </p>
        </Modal>
    </Card>
</template>
  
<script>
import config from "@/config";
import { getToken } from "../../libs/util";
const baseUrl = process.env.NODE_ENV === "development" ? config.baseUrl.dev : config.baseUrl.pro;
const baseImgeUrl = process.env.NODE_ENV === "development" ? config.baseImgUrl.dev : config.baseImgUrl.pro;
export default {
    name: "technicianInfo",
    data() {
        return {
            baseUrl: baseUrl,
            baseImgeUrl: baseImgeUrl,
            // 列表
            columns: [
                {
                    title: '技师头像',
                    align: "center",
                    key: 'tech',
                    slot: "techSlot"
                },
                {
                    title: '技师昵称',
                    align: "center",
                    key: 'tech_username',
                },
                {
                    title: '技师手机号',
                    align: "center",
                    key: 'tech_mobile',
                },
                {
                    title: '技师姓名',
                    align: "center",
                    key: 'name',
                },
                {
                    title: '身份证号',
                    align: "center",
                    key: 'card_no',
                },
                {
                    title: '身份证图片',
                    align: "center",
                    slot: 'imgSlot',
                },
                {
                    title: '健康证',
                    align: "center",
                    slot: 'imgSlot1',
                },
                {
                    title: '从业资格证',
                    align: "center",
                    slot: 'imgSlot2',
                },
                {
                    title: '个人相片',
                    align: "center",
                    slot: 'imgSlot3',
                },
                {
                    title: '营业执照',
                    align: "center",
                    slot: 'imgSlot4',
                },
                {
                    title: '状态',
                    align: "center",
                    render: (h, param) => {
                        let txt = "";
                        if (param.row.status == 0) {
                            txt = "待审核";
                        } else if (param.row.status == 1) {
                            txt = "审核通过";
                        } else if (param.row.status == 2) {
                            txt = '审核拒绝';
                        }
                        return h('div', txt);
                    },
                },
                {
                    title: '操作',
                    align: "center",
                    slot: 'makeSlot',
                    width: 210
                },
            ],
            // 数据
            list: [],
            total: 0,
            imgShow: false,
            imgShowUrl: '',

            search: {
                page: 1,
                limit: 10
            },

            tabValue: "0",
            showPaymentInfo: false,
            imgArr: [],
        }
    },
    methods: {
        // 查询技师信息
        getList() {
            this.$axios('/admin/tec/techAuthList', this.search).then(res => {
                this.list = res.data;
                this.total = res.total;
            });
        },
        searchs() {
            this.search.page = 1;
            this.getList();
        },
        reset() {
            this.search = {
                page: 1,
                limit: 10
            };
            this.getList();
        },
        changePage(page) {
            this.search.page = page;
            this.getList();
        },
        changeSize(size) {
            this.search.limit = size;
            this.getList();
        },
        showImg(url) {
            this.imgShow = true;
            this.imgShowUrl = url;
        },
        // tab切换
        tabClick(name) {
            this.search.type = name;
            this.getList();
        },
        showImgDao(row) {
            this.showPaymentInfo = true;
            this.imgArr = row.image;
        },
        audit(id, status) {
            let txt = "";
            if (status == 1) {
                txt = "<p>您确定要审核通过吗？</p>"
            } else {
                txt = "<p>您确定要审核拒绝吗？</p>"
            }
            this.$Modal.confirm({
                title: '审核技师',
                content: txt,
                onOk: () => {
                    this.$axios('/admin/tec/auth', { id: id, status: status }).then(res => {
                        this.$Message.success('操作成功');
                        this.getList();
                    });
                },
                onCancel: () => {
                    this.$Message.info('取消操作');
                }
            });
        }
    },
    created() {
        this.getList();
    }
}
</script>
<style>
.ivu-table-cell {
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
}
</style>
  